<?php

/**
 * 幻灯片右侧说明 小挂件
 */
class DepictWidget extends CoreWidget{
    public $code = 'index_depict_section';
    public $type;
    public $num;
    public $is_show;
    public $role;
    private $path;
    public function init(){
        if($this->getRole(Yii::app()->user->getState('user_role'),Yii::app()->user->getState('role_salt'),'manage_index_depict')){
            $this->role = true;
        }else{
            $this->role = false;
        }
        //获取section表信息
        $section_info = Section::model()->getFindSection($this->code);
        $this->type = $section_info->type;
        $this->num = $section_info->num;
        $this->is_show = $section_info->is_show;
        $assets = Yii::getPathOfAlias('application').DIRECTORY_SEPARATOR.'widgets'.DIRECTORY_SEPARATOR.'depict_block'.DIRECTORY_SEPARATOR.'statics'.DIRECTORY_SEPARATOR;
        //静态文件夹
        $this->path = Yii::app()->getAssetManager()->publish($assets, false, -1, YII_DEBUG);//强制生成
    }
    public function run(){
        if($this->is_show==1){
            if($this->role){
                Yii::app()->clientScript->registerScriptFile($this->path . '/codemirror/codemirror.js',CClientScript::POS_END);
                Yii::app()->clientScript->registerScriptFile($this->path . '/codemirror/xml.js',CClientScript::POS_END);
                Yii::app()->clientScript->registerScriptFile($this->path . '/codemirror/clike.js',CClientScript::POS_END);
                Yii::app()->clientScript->registerScriptFile($this->path . '/codemirror/php.js',CClientScript::POS_END);
                Yii::app()->clientScript->registerScriptFile($this->path . '/codemirror/javascript.js',CClientScript::POS_END);
                Yii::app()->clientScript->registerScriptFile($this->path . '/codemirror/css.js',CClientScript::POS_END);
                Yii::app()->clientScript->registerCssFile($this->path . '/codemirror/codemirror.css');
            }
            if($this->type==3){
                $info = SectionHistory::model()->getContent($this->code,3);
                $this->render('depict_block',array('info'=>CHtml::decode($info),'role'=>$this->role));
            }
        }
    }


}